#include "openmove_Prefix.h"
#include "MaterialEditor.h"

MaterialEditor :: MaterialEditor(CEGUI::Window *parent, SceneManager *sceneManager) : m_light(NULL), m_sceneManager(sceneManager)
{
	CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();
	m_window = wmgr.createWindow((CEGUI::utf8*)"DefaultWindow", (CEGUI::utf8*)"MaterialEditor");
	m_window->setVisible(false);
	m_window->setPosition(CEGUI::Point(0, 0.05f));
	m_window->setSize(CEGUI::Size(0.16f, 0.7f));
	parent->addChildWindow(m_window);

	m_diffuse = new RGBASlider("lightDiffuse", m_window, Vector4::ZERO, CEGUI::Point(0, 0), CEGUI::Size(1.0f, 0.25));
	m_ambient = new RGBASlider("lightAmbient", m_window, Vector4::ZERO, CEGUI::Point(0, 0.25), CEGUI::Size(1.0f, 0.25));
	m_specular = new RGBASlider("lightSpecular", m_window, Vector4::ZERO, CEGUI::Point(0, 0.5), CEGUI::Size(1.0f, 0.25));

	m_ok = (CEGUI::PushButton*)wmgr.createWindow("TaharezLook/Button", (CEGUI::utf8*)"lightOk");
	m_window->addChildWindow(m_ok);
	m_ok->setPosition(CEGUI::Point(0.f, 0.75f));
	m_ok->setSize(CEGUI::Size(1.0f, 0.25f));
	m_ok->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&MaterialEditor::handleOkEvent, this));
	m_ok->setText("Ok");
}

MaterialEditor :: ~MaterialEditor(void)
{
	delete m_diffuse;
	delete m_ambient;
	delete m_specular;
}

bool MaterialEditor :: handleOkEvent(const CEGUI::EventArgs& e)
{
	m_window->getParent()->activate();
	m_window->setVisible(false);

	return (true);
}

bool MaterialEditor :: isActive(void)
{
	return (m_window->isVisible() && m_window->isActive());
}

bool MaterialEditor :: isVisible(void)
{
	return (m_window->isVisible());
}

void MaterialEditor :: setVisible(bool visible)
{
	m_window->setVisible(visible);
}

void MaterialEditor :: updateSliders(Light const *light)
{
	//m_diffuse->updateSlider(light->getDiffuseColour());
	//m_specular->updateSlider(light->getSpecularColour());
	//m_ambient->updateSlider(m_sceneManager->getAmbientLight());
}

void MaterialEditor :: updateLight(Light *light)
{
	//light->setDiffuseColour(m_diffuse->m_color);
	//light->setSpecularColour(m_specular->m_color);
	//m_sceneManager->setAmbientLight(m_ambient->m_color);
}

void MaterialEditor :: attach(CEGUI::Window *parent)
{
	m_window->removeChildWindow(m_window->getParent());
	parent->addChildWindow(m_window);
}
